package com.mall.order.vo;

import com.mall.common.dto.MemberReceiveAddressDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author: 谢君臣
 * @Date: 2022/8/9-21:04
 * @version: 1.0
 * @function:
 */

public class OrderConformVo {
    // 收货人信息
    @Getter @Setter
    List<MemberReceiveAddressDTO> memberAddress;
    // 送货清单
    @Getter @Setter
    List<OrderItemVo> items;

    public Integer getCount() {
        int temp_count = 0;
        if (items!=null) {
            for (OrderItemVo item : items) {
                temp_count += item.getCount();
            }
        }
        return temp_count;
    }

    private Integer count;
    // 发票。。。
    // 优惠券。。。
    @Getter @Setter
    List<CouponVO> coupons;

    @ApiModelProperty(value = "订单总额")
    private BigDecimal totalAmount;

    @ApiModelProperty(value = "应付总额")
    private BigDecimal payAmount;

    @ApiModelProperty(value = "运费金额")
    BigDecimal freightAmount;

    @ApiModelProperty(value = "促销优化金额（促销价、满减、阶梯价）")
    BigDecimal promotionAmount;

    @ApiModelProperty(value = "积分抵扣金额")
    BigDecimal integrationAmount;

    @ApiModelProperty(value = "优惠券抵扣金额")
    BigDecimal couponAmount;

    @ApiModelProperty(value = "后台调整订单使用的折扣金额")
    BigDecimal discountAmount;

    @Getter @Setter
    @ApiModelProperty(value = "订单防重令牌")
    String OrderToken;


    public void setTotalAmount() {
        BigDecimal decimal = new BigDecimal("0");
        for (OrderItemVo item : items) {
            decimal = decimal.add(item.getPrice().multiply(new BigDecimal(item.getCount())));
        }
        this.totalAmount = decimal;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal decimal = new BigDecimal("0");
        for (OrderItemVo item : items) {
          decimal = decimal.add(item.getPrice().multiply(new BigDecimal(item.getCount())));
        }
        return decimal;
    }

    public BigDecimal getPayAmount() {
        return getTotalAmount();
//        return payAmount;
    }
}
